package main

import (
	"fmt"
	"sync"
	"time"
)

var sync_1 sync.WaitGroup

func write(ch chan int) {
	for i := 1; i <= 10; i++ {
		ch <- i
		fmt.Printf("写入数据 -%v成功\n", i)
		time.Sleep(time.Millisecond * 1000)
	}
	close(ch)
	sync_1.Done()
}

func read(ch chan int) {
	for v := range ch {
		fmt.Printf("读取数据 -%v成功\n", v)
		time.Sleep(time.Millisecond * 100)
	}
	sync_1.Done()
}

func main() {
	ch := make(chan int, 10)
	sync_1.Add(2)
	go write(ch)
	go read(ch)
	sync_1.Wait()
	fmt.Println("退出程序")
}
